package com.hzeport.bgs22emduty.inbound.lsapi;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzeport.bgs22emduty.config.SystemConfig;
import com.hzeport.bgs22emduty.config.login.LoginCompoentService;
import com.hzeport.bgs22emduty.config.login.UserInfoDetailVO;
import com.hzeport.bgs22emduty.config.systemLog.OperLog;
import com.hzeport.bgs22emduty.entity.ScreenDutyMaps;
import com.hzeport.bgs22emduty.entity.ScreenDutyMessage;
import com.hzeport.bgs22emduty.outbound.ScreenDutyMapsRepository;
import com.hzeport.bgs22emduty.service.ScreenDutyMessageService;
import com.hzeport.bgs22emduty.vo.ScreenNotice.ScreenNoticeSaveVO;
import com.hzeport.bgs22emduty.vo.ls.ScreenDutyMessageSaveVO;
import com.hzeport.bgs22emduty.vo.ls.ScreenDutyNoticeListLSAnnoSaveVO;
import com.hzeport.bgs22emduty.common.base.BaseResult;
import freemarker.template.TemplateException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * ${comments}
 *
 * @author code generator
 * @date 2023-02-14 09:39:44
 */
@RestController
@AllArgsConstructor
@RequestMapping("/screendutymessagels")
@Api(value = "screendutymessagels", tags = "值班信息管理ls")
@Slf4j
@CrossOrigin
public class ScreenDutyMessageLSController {

    private final ScreenDutyMessageService screenDutyMessageService;
    @Resource
    private LoginCompoentService loginCompoentService;
    private final SystemConfig systemConfig;
    private final ScreenDutyMapsRepository screenDutyMapsRepository;

    @ApiOperation(value = "保存")
    @RequestMapping(value = "savels",method = RequestMethod.POST)
    @OperLog(systemName = "ZBXX",description = "XXXZ")
    public BaseResult savels(@RequestBody ScreenDutyMessageSaveVO screenDutyMessageSaveVO, HttpServletRequest request) {
        return screenDutyMessageService.savels(screenDutyMessageSaveVO,request);
    }


    @ApiOperation(value = "上报总关")
    @RequestMapping(value = "escalation",method = RequestMethod.POST)
    @OperLog(systemName = "ZBXX",description = "XXSB")
    public BaseResult escalation(@RequestBody ScreenDutyMessageSaveVO screenDutyMessageSaveVO, HttpServletRequest request) {
        return screenDutyMessageService.escalation(screenDutyMessageSaveVO,request);
    }

    @ApiOperation(value = "导出文档")
    @RequestMapping(value = "exportDoc",method = RequestMethod.GET)
    public BaseResult exportDoc(@RequestParam("id") String id, HttpServletResponse response) throws IOException, TemplateException {
        return screenDutyMessageService.exportDoc(id,response);
    }

    @ApiOperation(value = "导出文档")
    @RequestMapping(value = "exportDocWithParam",method = RequestMethod.POST)
    public void exportDocWithParam(@RequestBody JSONObject pararm, HttpServletResponse response) throws IOException, TemplateException {
         screenDutyMessageService.exportDocWithParam(pararm,response);
    }

    @ApiOperation(value = "获取HbUrl", notes = "获取HbUrl")
    @GetMapping("/getHbUrl")
    public BaseResult<String> getHbUrl(@RequestParam(value = "customId" , required = false) String customId) {
        if (StringUtils.isBlank( customId )) {
            return BaseResult.ok( StringUtils.isNotBlank(systemConfig.getAddUrl())?systemConfig.getAddUrl():"");
        }else {
            ScreenDutyMaps dutyMaps = screenDutyMapsRepository.getOne(new LambdaQueryWrapper<ScreenDutyMaps>()
                    .eq(ScreenDutyMaps::getCustomCode, customId) , false );
            return BaseResult.ok(StringUtils.isNotBlank(dutyMaps.getAddUrl())?dutyMaps.getAddUrl():"");
        }
    }

}
